package com.own.core.html.component;


import org.apache.wicket.model.LoadableDetachableModel;

import com.own.core.object.Dao;
import com.own.core.operation.DbOperation;
import com.sun.org.apache.bcel.internal.generic.DADD;

/**
 * detachable model for an instance of contact
 * 
 * @author igor
 * 
 */
public class DetachableDaoModel extends LoadableDetachableModel
{
    private long id;
    private  Dao dao;
  

    /**
     * @param c
     */
    public DetachableDaoModel(Dao dao)
    { 
    	super(dao);
    	this.dao=dao;
   
       
    }

 
    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode()
    {
        return Long.valueOf(id).hashCode();
    }

    /**
     * used for dataview with ReuseIfModelsEqualStrategy item reuse strategy
     * 
     * @see org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(final Object obj)
    {
        if (obj == this)
        {
            return true;
        }
        else if (obj == null)
        {
            return false;
        }
        else if (obj instanceof DetachableDaoModel)
        {
            DetachableDaoModel other = (DetachableDaoModel)obj;
            return other.id == this.id;
        }
        return false;
    }

    /**
     * @see org.apache.wicket.model.LoadableDetachableModel#load()
     */
    protected Object load()
    {
    	DbOperation.getME().refresh(dao);
    	return dao;

    }


	public long getId() {
		return id;
	}


	public Dao getDao() {
		return dao;
	}


	public void setId(long id) {
		this.id = id;
	}


	public void setDao(Dao dao) {
		this.dao = dao;
	}
}